// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

function humpToUnderline(content:string):string {
	if (content && content.length <= 1) {
		return content;
	}
	return content.replace(/([a-z0-9_][A-Z])/g,(v)=>`${v.slice(0,1)}_${v.slice(1).toLowerCase()}`);
}

function underlineToHump(content: string): string{
	if (content && content.length <= 1) {
		return content;
	}
	return content.replace(/\S_\w/g, (v: string): string => {
		let curList: Array<string> = v.split('_');
		if (curList[1]) { curList[1] = curList[1].toUpperCase(); }
		return curList.join('');
	});
}
// 当插件被激活触发
export function activate(context: vscode.ExtensionContext) {

	// 当您的插件被激活时，这行代码只会被执行一次
	console.log('Congratulations, your extension "wen-humpEffectUnderline" is now active!');

	// 驼峰命名 转 下划线命名
	let disposableHump = vscode.commands.registerTextEditorCommand('wen-humpEffectUnderline.humpToUnderline', (textEditor,edit) => {
	
		const selectText = textEditor.document.getText(textEditor.selection);// 获取选中文本
		const changeText = humpToUnderline(selectText);

		edit.replace(textEditor.selection, changeText);

		//vscode.window.showInformationMessage('驼峰命名 转 下划线命名!');

	});

	// 下划线命名 转 驼峰命名
	let disposableUnderline = vscode.commands.registerTextEditorCommand('wen-humpEffectUnderline.underlineToHump', (textEidtor, edit) => {
		const selectText = textEidtor.document.getText(textEidtor.selection);

		const changeText = underlineToHump(selectText);

		edit.replace(textEidtor.selection, changeText);

		//vscode.window.showInformationMessage('下划线命名 转 驼峰命名!');

	});



	context.subscriptions.push(disposableHump);
	context.subscriptions.push(disposableUnderline);

}

// 当插件被停用时触发
export function deactivate() {}
